-
Notifications
You must be signed in to change notification settings - Fork 21
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
add odd?
and even?
to the loop tag
#232
Conversation
src/marten/template/tag/for/loop.cr
Outdated
def odd? | ||
!even? | ||
end | ||
|
||
def even? | ||
@index % 2 == 0 | ||
end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why not use the existing #odd?
and #even?
methods?
def odd? | |
!even? | |
end | |
def even? | |
@index % 2 == 0 | |
end | |
def odd? | |
@index.odd? | |
end | |
def even? | |
@index.even? | |
end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Whoa!! I haven't thought about it. Thanks @ellmetha. I'll make the change.
loop.index = 2 | ||
loop.odd?.should eq false |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would expect this to be in another spec example (eg. returns false if the index is not odd
).
loop.index = 1 | ||
loop.even?.should eq false |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same remark here: this could be in its own spec example (returns false if the index is not even
).
Thanks for adding this! |
Used modulo 2 to check for "even-ness". Zero is considered as even.
#201